import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    redirect: '/article-list',
    component: () => import('@/views/home/index.vue'),
    children: [
      {
        path: '/article-list',
        name: 'articleList',
        component: () => import('@/views/article-list/index.vue')
      },
      {
        path: '/about',
        name: 'About',
        component: () => import('@/views/about/index.vue')
      },
      {
        path: '/article/:id',
        name: 'Article',
        props: true,
        component: () => import('@/views/article/index.vue')
      },
      {
        path: '/result-article/:label',
        name: 'ArticleResult',
        props: true,
        component: () => import('@/views/result-article/index.vue')
      }
    ]
  }, {
    path: '/login',
    name: 'Home',
    component: () => import('@/views/login/index.vue')
  },
  {
    path: '/admin',
    name: 'Admin',
    component: () => import('@/views/admin/index.vue'),
    redirect: '/adminArticleList',
    children: [
      {
        path: '/adminArticleList',
        name: 'adminArticleList',
        component: () => import('@/views/admin-article/index.vue')
      }, {
        path: '/addarticle/:id',
        props: true,
        name: 'add-article',
        component: () => import('@/views/add-article/index.vue')
      }
    ]
  }
]

const router = new VueRouter({
  routes,
  scrollBehavior (to, from, saveTop) {
    if (saveTop) {
      return saveTop
    } else {
      return { x: 0, y: 0 }
    }
  }
})

export default router
